package model

import (
	"gorm.io/gorm"
	"time"
)

// Knowledge 表示QA类型的知识库条目
type Knowledge struct {
	gorm.Model // 包含 ID、CreatedAt、UpdatedAt、DeletedAt 字段
	//Name        string    `gorm:"type:varchar(100);not null;comment:知识条目名称" json:"name"`
	Question string `gorm:"type:text;not null;comment:问题内容" json:"question"`
	Answer   string `gorm:"type:text;not null;comment:答案内容" json:"answer"`
	UserId   uint   `gorm:"not null;index;comment:所属用户ID" json:"user_id"`
	//Collection  string    `gorm:"type:varchar(100);not null;comment:Qdrant集合名称" json:"collection"`
	QVectorId    int64      `gorm:"type:varchar(100);not null;comment:问题的向量ID" json:"q_vector_id"`
	AVectorId    int64      `gorm:"type:varchar(100);comment:答案的向量ID" json:"a_vector_id,omitempty"`
	Category     string     `gorm:"type:varchar(100);comment:知识分类" json:"category,omitempty"`
	Tags         string     `gorm:"type:varchar(255);comment:标签,多个标签用逗号分隔" json:"tags,omitempty"`
	Source       string     `gorm:"type:varchar(255);comment:知识来源" json:"source,omitempty"`
	AccessCount  int        `gorm:"default:0;comment:访问次数" json:"access_count"`
	LastAccessAt *time.Time `gorm:"comment:最后访问时间" json:"last_access_at,omitempty"`
}

// NewKnowledge 创建一个新的知识条目
func NewKnowledge(question, answer string, userId uint) *Knowledge {
	return &Knowledge{
		Question: question,
		Answer:   answer,
		UserId:   userId,
	}
}

// TableName 设置表名
func (Knowledge) TableName() string {
	return "t_knowledge"
}
